package com.ce.source.analysis.thread;

/**
 * @author ：xiaopingzhang8@creditease.cn
 * @Description ：整数相加
 * @ClassName ：IntegerLock
 * @Company ：普信恒业科技发展（北京）有限公司
 * @date ：2017/11/30 18:32
 */
public class IntegerLock {
    static volatile Integer i = 0;

    public static class AddThread extends Thread {
        @Override
        public void run() {
            synchronized (IntegerLock.class) {
                for (int k = 0; k < 100000; k++) {
                    i++;
                }
            }

        }
    }

    public static void main(String[] args) throws Exception {
        AddThread t1 = new AddThread();
        AddThread t2 = new AddThread();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }
}
